<?php

namespace BaseBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

/**
 * TestUser
 *
 * @ORM\Table(name="test_user")
 * @ORM\Entity(repositoryClass="BaseBundle\Repository\TestUserRepository")
 */
class TestUser implements \JsonSerializable
{
    /**
     * @ORM\OneToMany(targetEntity="BaseBundle\Entity\TestUserAddress",mappedBy="testUser")
     */
    private $testUserAddress = null;

    function __construct()
    {
        $this->testUserAddress = new ArrayCollection();
    }

    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     * @ORM\Column(name="name", type="string", length=30, nullable=true, options={"comment":"名称"})
     */
    private $name;

    /**
     * Set name
     *
     * @param string $name
     *
     * @return TestUser
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Add testUserAddress
     *
     * @param \BaseBundle\Entity\TestUserAddress $testUserAddress
     *
     * @return TestUser
     */
    public function addTestUserAddress(\BaseBundle\Entity\TestUserAddress $testUserAddress)
    {
        $this->testUserAddress[] = $testUserAddress;

        return $this;
    }

    /**
     * Remove testUserAddress
     *
     * @param \BaseBundle\Entity\TestUserAddress $testUserAddress
     */
    public function removeTestUserAddress(\BaseBundle\Entity\TestUserAddress $testUserAddress)
    {
        $this->testUserAddress->removeElement($testUserAddress);
    }

    /**
     * Get testUserAddress
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getTestUserAddress()
    {
        return $this->testUserAddress;
    }

    function jsonSerialize()
    {
        $data = [];
        foreach ($this as $key=>$val){
            if ($val !== null){
                $data[$key] = $val;
            }else{
                $data[$key] = '';
            }
        }

        return $data;
    }
}
